package com.test;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.ArrayList;

public class MemberDAO {

	String driver ="oracle.jdbc.driver.OracleDriver";
	String url="jdbc:oracle:thin:@211.183.2.30:1521:orcljava";
	String uid="java16", pw="java16";
	Connection con = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
/*public MemberDAO() {
		try {
			Class.forName(driver);
		} catch(ClassNotFoundException e) {
			e.printStackTrace();
		}
	} */
	
	public ArrayList<MemberDTO> select() {
		ArrayList<MemberDTO> list =  new ArrayList<MemberDTO>();
		try {
			con = DriverManager.getConnection(url,uid,pw);
			String sql = "select id,pw,name,tel,addr,jumin,email,birth,job,intro,m.gno,gno," +
					"regdate,condate from member m , grade g where m.gno=g.gno";
			pstmt = con.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next()) {
				MemberDTO dto = new MemberDTO();
				dto.setId(rs.getString("id"));
				dto.setPw(rs.getString("pw"));
				dto.setName(rs.getString("name"));
				dto.setTel(rs.getString("tel"));
				dto.setAddr(rs.getString("addr"));
				dto.setJumin(rs.getString("jumin"));
				dto.setEmail(rs.getString("email"));
				dto.setBirth(rs.getDate("birth").toString());
				dto.setJob(rs.getString("job"));
				dto.setIntro(rs.getString("intro"));
				dto.setGno(rs.getInt("gno"));
				dto.setRegdate(rs.getDate("regdate"));
				dto.setCondate(rs.getDate("condate"));
				list.add(dto);
			}
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(rs != null) rs.close(); 
				if(rs != null) pstmt.close();
				if(rs != null) con.close();
			} catch(SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	public void insert(MemberDTO dto) {
		
	}
	
	public void update(MemberDTO dto) {
		
	}
	
	public void delete(String id, String pw) {
		
	}
	
}
